﻿<?xml version="1.0" encoding="utf-8"?>
<!--
This is an alternative xslt file which uses a sorting display which is closer to the default microsoft one.
(with images for sort direction if sorting on soreable fields though)
First the selected sorting is displayed. The other sorting fields are shown in ascending order on the display name
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/SearchActions">
    <!--<xsl:template name="SortActionsTemplate">    -->
    <div class="srch-sort-right">

      <xsl:for-each select="SortAction" >
        <!-- Show the selected result first-->
        <xsl:sort order="descending" select="@isSelected"/>
        <!-- Then order by name-->
        <xsl:sort order="ascending" select="DisplayName"/>
        <xsl:variable name="url" select="SortActionUrl"/>
        <xsl:variable name="selectedSort" select="SelectedSortDirection"/>
        <xsl:variable name="isRankprofile" select="IsRankProfile"/>
        <xsl:variable name="isSelected" select="@isSelected"/>
        <xsl:choose>
          <xsl:when test="$isSelected = 'true'">
            Results by <xsl:value-of select="DisplayName"/>
            <xsl:if test="$isRankprofile = 'False'">
              <xsl:if test="$selectedSort = '+'">
                <a href="{$url}">
                   <img style="border:0px;" src="/_layouts/images/ewr132.gif" alt="Switch Sort Direction (currently ascending)"></img>
                </a>
              </xsl:if>
              <xsl:if test="$selectedSort = '-'">
                <a href="{$url}">
                  <img src="/_layouts/images/ewr131.gif" style="border:0px;"  alt="Switch Sort Direction (currently descending)"></img>
                </a>
              </xsl:if>
            </xsl:if>
          </xsl:when>
          <xsl:otherwise>
            <a href="{$url}">
              View by <xsl:value-of select="DisplayName"/>
            </a>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text xml:space="preserve"> | </xsl:text>
      </xsl:for-each>
    </div>
  </xsl:template>
</xsl:stylesheet>
